#define _CRT_SECURE_NO_WARNINGS 1







#include<iostream>
#include<algorithm>

using namespace std;

typedef long long LL;
const int N = 5e4 + 10;

struct node
{
	int w;
	int s;
}a[N];
int n;
bool cmp(node& x, node& y)
{
	//return max(-x.s, x.w - y.s) < max(-y.s, y.w - x.s);
	return x.s + x.w < y.s + y.w;
}
int main()
{
	cin >> n;
	for (int i = 1;i <= n;++i)
		cin >> a[i].w >> a[i].s;
	sort(a + 1, a + 1 + n, cmp);
	LL ret = -1e9-10;
	LL w = 0;
	for (int i = 1;i <= n;i++)
	{
		ret = max(w - a[i].s, ret);
		w += a[i].w;
	}
	cout << ret;
	return 0;
}